<template>
  <div>
    <!-- 刷新缓存 -->
    <a-modal
      title="刷新缓存"
      :keyboard="false"
      :maskClosable="false"
      :closable="false"
      v-model="show"
      @cancel="cancelReloadCache"
      @ok="handleReloadCache">
      <a-form :form="form">

        <a-form-item
          label="法人行"
          :labelCol="{span: 5}"
          :wrapperCol="{span: 16, offset: 1}">
          <a-select v-if="this.user.admin"
                    mode="default"
                    :allowClear="true"
                    style="width: 100%"
                    v-model="instId">
            <a-select-option v-for="r in instIdData" :key="r.label">{{r.label}}-{{r.value}}</a-select-option>
          </a-select>
        </a-form-item>
          <a-form-item label="刷新缓存类型" :labelCol="{span: 5}"
                       :wrapperCol="{span: 16, offset: 1}">
            <a-select placeholder="请选择刷新缓存类型" v-model="cacheType" mode="default"
                      :allowClear="true"
                      style="width: 100%">
              <a-select-option value="">请选择</a-select-option>
              <a-select-option value="00">交易权限</a-select-option>
              <a-select-option value="01">渠道/通道状态</a-select-option>
              <a-select-option value="02">卡BIN信息</a-select-option>
              <a-select-option value="03">系统参数</a-select-option>
              <a-select-option value="04">错误码映射关系</a-select-option>
            </a-select>
          </a-form-item>
      </a-form>
    </a-modal>
  </div>
</template>
<script>

  export default {
    beforeCreate() {
      this.form = this.$form.createForm(this)
    },
    props: {
      reloadCacheModelVisible: {
        default: false
      },
      user: {
        required: true
      }
    },
    data() {
      return {
        instIdData: [],
        instId:"",
        cacheType:"",
        state: {
          reloadCacheChecked: false,
        },
      }
    },
    computed: {
      show: {
        get: function () {
          return this.reloadCacheModelVisible
        },
        set: function () {
        }
      },
    },
    mounted() {
      this.$get('admin/upmporg/getInstList').then((r) => {
        this.instIdData = r.data
      })
    },
    methods: {
      isMobile () {
        return this.$store.state.setting.isMobile
      },
      cancelReloadCache () {
        this.form.resetFields()
        this.$emit('cancel')
      },

      handleReloadCache () {


        if(!this.instId){
          this.$message.error('请选择法人行！');
          return false;
        }
        if(!this.cacheType){
          this.$message.error('请选择刷新缓存类型！');
          return false;
        }


        this.$post('/admin/reloadCache/edit', {
          instId: this.instId,
          cacheType: this.cacheType,
        }).then((res) => {
          if (res.data.code==="100000") {
            this.state.reloadCacheChecked = false
            this.$emit('success');
            this.form.resetFields();
          } else {
            this.state.reloadCacheChecked = false
            this.$message.error(res.data.message)
          }
        })


      },

    }
  }
</script>
<style lang="less">

</style>
